package com.ywm.vod.dynamic_proxy;

import com.ywm.vod.dynamic_proxy.factory.UsbKingFactory;
import com.ywm.vod.dynamic_proxy.handle.MyShellHandle;
import com.ywm.vod.dynamic_proxy.service.UsbShell;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

public class MainShop {
    public static void main(String[] args) {
        //创建目标对象
        UsbShell factory = new UsbKingFactory();
        //创建InvocationHandler对象（对目标方法进行加工）
        InvocationHandler handle = new MyShellHandle(factory);
        //创建代理对象
        UsbShell proxy=(UsbShell)Proxy.newProxyInstance(
                factory.getClass().getClassLoader(),
                factory.getClass().getInterfaces(),
                handle
        );
        //通过代理执行方法
        float price = proxy.sell(2);
        System.out.println(price);
    }
}
